/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import framework.GameObject;
import framework.Key;
import framework.Screen;
import framework.Util;
import framework.gameAPI.Sprite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;

/**
 *
 * @author edilson
 */
public class Bomba extends GameObject {

    private Sprite sprite;
    private static final int[] ANIM_MOVE = {0, 1};
    private static final int[] ANIM_DEAD = {2, 3, 4, 5, 6, 7, 8};
    private int state;
    public static final int STATE_MOVING = 0;
    public static final int STATE_DYING = 1;
    public static final int STATE_DEAD = 2;

    public Bomba(int x, int y) {
        this.image = Util.loadImage(Global.IMG_BOMBA);

        sprite = new Sprite(image, 25, 25);
        sprite.setAnimationDelay(5);
        sprite.setFrameSequence(ANIM_MOVE);
        state = STATE_MOVING;

        this.x = x;
        this.y = y;
        this.width = image.getWidth(null);
        this.height = image.getHeight(null);
        this.width = 25;
        this.height = 25;

        this.visible = true;
        this.power = 10;

    }

    @Override
    public void update() {
        switch (state) {
            case STATE_MOVING:
                if(power<=0){
                    state = STATE_DYING;
                    sprite.setFrameSequence(ANIM_DEAD);
                }
                
                speedY = 3;
                y += speedY;
                if (y > Screen.getHeight()) {
                    state = STATE_DEAD;
                }
                break;
            case STATE_DYING:
                sprite.setAnimationDelay(3);
                if (sprite.animationEnded()) {
                    state = STATE_DEAD;
                }
                break;
            case STATE_DEAD:
                setVisible(false);
                break;
        }

    }

    @Override
    public void paint(Graphics g) {
        if (visible) {
            //g.drawImage(image, x, y, null);
            sprite.setX(x);
            sprite.setY(y);
            sprite.paint(g);
        }
    }

    public int getState() {
        return state;
    }
    

}
